package utils;

import java.lang.reflect.InvocationTargetException;

import dao.implementation.ArticleDAOImplementation;
import dao.implementation.AuthorDAOImplementation;
import dao.implementation.BookDAOImplementation;
import dao.implementation.UserDAOImplementation;


public class DAOFactory
{
	public enum DAOClassName
	{
		USER(UserDAOImplementation.class.getName()),
		AUTHOR(AuthorDAOImplementation.class.getName()),
		ARTICLE(ArticleDAOImplementation.class.getName()),
		BOOK(BookDAOImplementation.class.getName());
		
		String name;
		
		DAOClassName(String name){ this.name = name; }
		
		public String getName()
		{
			return this.name;
		}
	}
	
	public static Object getDAOInstance(DAOClassName name)
	{
		try
		{
			return Class.forName(name.getName()).getDeclaredConstructor().newInstance();
		}
		catch (InstantiationException e) {e.printStackTrace();}
		catch (IllegalAccessException e) {e.printStackTrace();}
		catch (IllegalArgumentException e) {e.printStackTrace();}
		catch (InvocationTargetException e) {e.printStackTrace();}
		catch (NoSuchMethodException e) {e.printStackTrace();}
		catch (SecurityException e) {e.printStackTrace();}
		catch (ClassNotFoundException e) {e.printStackTrace();}
		
		return null;
	}
}





